﻿using System;
using System.Collections.Generic;
using System.Data.EntityClient;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace Icoders.MarketTracker.Data
{
    public class AppInfo
    {
#if(BAT)
      public static string con = EFConnectionBuilder.Build("barberry.arvixe.com", "MarketTracker","icoders","icoders2012");
#elif(KIMFAY)
        public static string con = EFConnectionBuilder.Build("barberry.arvixe.com", "MarketTracker-kimfay", "icoders", "icoders2012");
#else
        public static string con = EFConnectionBuilder.Build(".", "MarketTracker","sa","1234");
#endif
    }
    public class EFConnectionBuilder
    {
        public static string Build(string host,string db,string username,string password)
        {
            // Specify the provider name, server and database.
            string providerName = "System.Data.SqlClient";
            string serverName = host;//"."
            string databaseName = db;//"MarketTracker";

            // Initialize the connection string builder for the
            // underlying provider.
            SqlConnectionStringBuilder sqlBuilder =
                new SqlConnectionStringBuilder();

            // Set the properties for the data source.
            sqlBuilder.DataSource = serverName;
            sqlBuilder.InitialCatalog = databaseName;
            sqlBuilder.PersistSecurityInfo = true;
            sqlBuilder.UserID = username;// "sa";
            sqlBuilder.Password = password;// "1234";
            sqlBuilder.MultipleActiveResultSets = true;
            

            // Build the SqlConnection connection string.
            string providerString = sqlBuilder.ToString();

            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder =
                new EntityConnectionStringBuilder();

            //Set the provider name.
            entityBuilder.Provider = providerName;
            
            // Set the provider-specific connection string.
            entityBuilder.ProviderConnectionString = providerString;
            // Set the Metadata location.
            entityBuilder.Metadata = @"res://*/EF.MTModel.csdl|res://*/EF.MTModel.ssdl|res://*/EF.MTModel.msl";
            Console.WriteLine(entityBuilder.ToString());
            return entityBuilder.ToString();
        }
    }
}
